package com.inossem.warehousestorage_inossem.request.allocation;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.allocation.AllocationOutOverViewBean;
import com.inossem.warehousestorage_inossem.bean.allocation.AllocationOutSearchMatsRequestBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * 查询物料列表
 *
 * @author 詹建宇
 * @time on 2018/3/30 11:01
 * @email jianyu.zhan@inossem.com
 */
public class AllocationOutStorageSearchMaterialsRequest extends Request {

    public static String request(Context context, String condition, String location_id, String batch, String stock_input_id, GsonBeanListener gsonBeanListener) {

        String tag;
        Map<String, String> params = new HashMap<>();
        if (!TextUtils.isEmpty(condition)) params.put("condition", condition);
        if (!TextUtils.isEmpty(location_id)) params.put("location_id", location_id);
        if (!TextUtils.isEmpty(batch)) params.put("batch", batch);
        if (!TextUtils.isEmpty(stock_input_id)) params.put("stock_input_id", stock_input_id);
        String url = RequestManage.getUrl(context, RequestConstant.URL_ALLOCATION_OUT_SEARCH_MAT + RequestManage.mapEncodeToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                AllocationOutOverViewBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), AllocationOutOverViewBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
        return tag;
    }
}
